value dispath map (time,owner,event) =
  (
    match event with
    [ `Wait  -> (Printf.printf "%s wait %f msc\n" owner#name time)
    | `Move (x,y)-> (Printf.printf "%s stan in %dx%d\n" owner#name x y)
    | `Go -> (Printf.printf "%s stan want go\n" owner#name)
    | `Attack a -> (Printf.printf "%s try attack %s\n" owner#name a#name)
    | `Wakeup -> (Printf.printf "%s wakeup\n" owner#name)
    | _ -> failwith "reaction unknow"
    ];
(*     owner#p_print; *)
    try
      match event with
      [ `Wait  -> (*assert False*) (0.1,`Wait)
      | _ when owner#state = `Die -> (0.0, `Die)
      | `Wakeup -> 
        (
          owner#set_state `Run;
          (0.0,`Go)
        )
      | _ when owner#state = `Stun -> (5.0,`Wakeup)
      | `Attack a -> 
        (
          a#attack_me owner;
          (0.0,`Go)
        )
      | `Go -> 
        match map#next_step_opt owner with
        [ None ->
          (
            owner#set_path (map#search_path (map#position owner) owner#target);
            (0.0,`Go)
          )  
        | Some (p,_) -> (owner#move_delay,`Move p)
        ]
      | `Move p -> 
        match map#real_move owner p with
        [ `Ok -> 
          (
            owner#do_step p;
            match map#next_step_opt owner with
            [ Some (p,_) -> (owner#move_delay,`Move p)
            | None ->
              (
                owner#set_target map#free_point;            
                (0.1,`Go)
              )
            ]
          )
        | `Occupied other -> 
          match other with
          [  [] -> assert False 
          |  [a::_] -> 
            (
              owner#set_path (map#search_path (map#position owner) owner#target);
              if map#can_next_step owner then (0.0,`Go) else (0.0,`Attack a)
            )
          ]
        | `Blocked -> assert False 
        ]
      | x -> failwith "reaction unknow"
      ]
    with [Astar.No_solution -> 
      (
        owner#set_target map#free_point;
        (0.1,`Go)
      )
    ]
  );